#pragma once

#include<iostream>

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include"Common.hpp"



class InetAddr
{
    public:
    InetAddr()
    {}
    InetAddr(uint16_t port)
    :_port(port)
    ,_ip("")
    {
        bzero(&_local, sizeof(_local));
        _local.sin_family = AF_INET;
        _local.sin_port = ::htons(_port);
    }
    InetAddr(sockaddr_in& local)
    :_local(local)
    {
        _port = ntohs(local.sin_port);

        char ipbuffer[1024];
        const char* ip = ::inet_ntop(AF_INET, &_local.sin_addr, ipbuffer, sizeof(ipbuffer));
        _ip=ipbuffer;
        

    }
    struct sockaddr* Addptr()
    {
        return CONV(&_local);
    }
    socklen_t Sizeptr()
    {
        return sizeof(_local);
    }
    std::string IP()
    {
        return _ip;
    }
    uint16_t Port()
    {
        return _port;
    }
    std::string Addr()
    {
        return _ip + std::to_string(_port);
    }
    bool operator==(const InetAddr& tmp)
    {
        return _ip == tmp._ip  && _port == tmp ._port;
    }
    ~InetAddr()
    {

    }
    private:
    struct sockaddr_in _local;
    uint16_t _port;
    std::string _ip;




};